<template>
	<div>
		<!-- <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad"> -->
		<div class="connet" v-for="(item,index) in list" :key="index">
			<h2>{{ month }}月 {{ day }}日</h2>
		</div>
		<ul>
			<li v-for="(it,index) in lis" :key="index" @click="jump(it.id)">
				<div class="item_left">
					<p class="p1">{{ it.title }}</p>
					<p class="p2">{{ it.hint }}</p>
				</div>
				<div class="item_right">
					<img :src="it.images[0]">
				</div>
				<div class="clear"></div>
			</li>
		</ul>
		<!-- </van-list> -->
	</div>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				loading: false,
				finished: false,
				lis: [],
				date1: "20201217",
				date: [],
				date2:"",
				oldlist:[]
			};
		},
		mounted() {
			this.gettime()
			this.history()
			window.onscroll=()=> {
				var scrollTop =document.documentElement.scrollTop || document.body.scrollTop //变量windowHeight是可视区的高度
				var windowHeight =document.documentElement.clientHeight || document.body.clientHeight //变量scrollHeight是滚动条的总高度
				var scrollHeight =document.documentElement.scrollHeight || document.body.scrollHeight
				if (scrollTop + windowHeight == scrollHeight) {
					this.date2--
					// console.log(this.date2)
				}
			}
		},
		watch:{
			date2:function(){
				// console.log(111)
				this.history()
				// console.log(this.lis)
				// console.log(this.lis[].title)
				// for(let i=0; i<this.lis.length; i++){
				// 	console.log(this.lis[i].title)
				// }
			}
		},
		methods: {
			gettime: function() {
				let data = new Date()
				let year = data.getFullYear()
				let month = data.getMonth() + 1

				let day = data.getDate()

				this.month = check(month)
				this.day = check(day)
				this.year = check(year)

				function check(i) {
					let num = (i < 10) ? ("0" + i) : i;
					return num;
				}

				this.date1 = String(year) + String(month) + String(day)
				this.date2 = Number(this.date1)
				// console.log(this.date2)
			},
			history: function() {
				this.$http.get("http://chonghekj.com/daily/index.php/Home/daily/before", {
						params: {
							date: this.date2
						}
					})
					.then((res) => {
						// console.log(res)
						this.oldlist = res.data.stories
						// console.log(this.oldlist)
						for(let i=0; i<this.oldlist.length; i++){
							this.lis.push(this.oldlist[i])
						}
					})
			},
			jump:function(id){
				console.log(id)
				this.$router.push({
					path:'/xq',
					query:{id}
				})
			}
		},
	};
</script>

<style>
</style>
